package cn.wubo.soap;

import cn.wubo.soap.model.BookRequest;
import cn.wubo.soap.model.BookResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;

@Endpoint
public class BookEndpoint {

    private static final String NAMESPACE_URI = "https://github.com/wb04307201/SpringBoot";

    private BookRepository bookRepository;

    @Autowired
    public BookEndpoint(BookRepository bookRepository) {
        this.bookRepository = bookRepository;
    }

    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "BookRequest")
    @ResponsePayload
    public BookResponse getBook(@RequestPayload BookRequest request) {
        BookResponse response = new BookResponse();
        response.setBook(bookRepository.findBook(request.getBook().getName()));
        return response;
    }
}
